import useDictStore from '@/store/modules/dict'
import { http } from '@/utils/http'

// 新增
export const appAdd = (data?: object) => {
  return http.request('post', '/app/app', { data })
}
// 编辑
export const costMgtUpdate = (data?: object) => {
  return http.request('post', '/app/update', { data })
}

// 列表
export const getList = (params?: object) => {
  return http.request('get', '/manage/apiInfo/apis', { params })
}

/**
 * 查询接口发布审批列表
 * @param params
 * @returns
 */
export const getCheckApisList = (params?: object) => {
  return http.get<{}, HttpPaginationResponse>('/manage/apiInfo/checkApis', { params })
}

// 详情信息
export const getDetail = (params?: number) => {
  return http.request('get', '/manage/approve/apiApplyInfo', {
    params: { applyId: params },
  })
}

/**
 * 删除接口
 * @param ids
 * @returns
 */
export const deleteApi = (ids: string) => {
  return http.request('delete', '/manage/apiInfo/', {
    params: {
      ids,
    },
  })
}

/**
 * 接口审核
 * @param data
 * @returns
 */
export const check = (data?: object) => {
  return http.request('post', '/manage/apiInfo/check', { data })
}

/**
 * 撤回接口发布申请
 * @param id
 * @returns
 */
export const revokeApply = (id: string) => {
  const { api_check_status } = useDictStore().getDicts('api_check_status')
  return http.request('post', '/manage/apiInfo/check', {
    data: {
      id,
      status: api_check_status.getLabel('已撤回'),
    },
  })
}

/**
 * 接口启用状态修改
 * @param payload
 * @returns
 */
export const changeStatus = (payload?: ChangeStatusData) => {
  return http.post('/manage/apiInfo/enabled', { data: payload })
}

export type ChangeStatusData = {
  id: string
  status: string
  opinion: string
}
